package com.liliang.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liliang.entity.IdMapping;
import com.liliang.entity.Stock;
import com.liliang.service.IIdMappingService;
import com.liliang.service.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liliang
 * @since 2021-11-04
 */
@Controller
@RequestMapping("/idMapping")
public class IdMappingController {

    @Autowired
    IIdMappingService iims;

    @Autowired
    IStockService iss;

    @GetMapping("/updatebyStatus")
    @ResponseBody
    public boolean updatebyStatus(Long OrdersId){
        IdMapping idMapping=new IdMapping();
        idMapping.setStatus("C001-20");
        return iims.update(idMapping,new QueryWrapper<IdMapping>().eq("ORDER_ID",OrdersId));
    }

    @GetMapping("/updatebyStatusByStock")
    @ResponseBody
    public boolean updatebyStatusByStock(Long StockId){
        IdMapping idMapping=new IdMapping();
        idMapping.setStatus("C001-40");
        return iims.update(idMapping,new QueryWrapper<IdMapping>().eq("STOCK_ID",StockId));
    }

    @GetMapping("/updatebyStatusByStock2")
    @ResponseBody
    public boolean updatebyStatusByStock2(Long StockId){
        IdMapping idMapping=new IdMapping();
        idMapping.setStatus("C001-60");
        if (iims.update(idMapping,new QueryWrapper<IdMapping>().eq("STOCK_ID",StockId))){
            Stock stock=new Stock();
            stock.setId(StockId);
            stock.setSubmitDate(LocalDateTime.now());
            return iss.updateById(stock);
        }
        return false;
    }


}

